import $ from "jquery";
import {url} from "../../util/config";
import {success,error} from "../../util/responseStatus";
import {message} from "antd";
import login from "../login";
function getNewLogin(items) {
    return insertRole(items)
}
export default function insertRole(items) {
    console.log(items);
    let token = localStorage.getItem("token")
    let status;
    $.ajax({
        async:false,
        headers: {
            'Accept': "application/json",
                'Authorization': token
        },
        url: url.api_url+`Role/InsertRole`,
        type: 'POST',
        contentType:"application/json",
        data: JSON.stringify({
                 ROLE_NAME:items.roleName,    //角色名称
                 ROLE_DESC:items.roleDesc,   //角色描述
                 ROLE_TYPE:items.roleType,  //角色类型
                 ROLE_BIND_MODULEID_LIST:items.rolePermission, //角色绑定的moduleId数组
            }
        ),
        success: function (result) {
            //result=0k
            status = result.result
            if(status=="Token過期請重新登錄"){
                login(localStorage.getItem("account"), localStorage.getItem("password"));
                status = getNewLogin(items)
            }else {
                if(status=="ok"){
                    message.success("新增成功")
                }else {
                    message.error("新增失败")
                }
            }
        },
        error:function (error) {
            status = "error"
            message.error("请求异常")
        }
    })
    return status;
    // return 'ok'
}
